home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / lmemccpy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  879 b   |  52 lines

  1. #ifdef __GNUC__
  2. #ifdef __MSHORT__
  3. #include "lib.h"
  4.  
  5. /*
  6.  * memccpy - copy bytes up to a certain char
  7.  *
  8.  * CHARBITS should be defined only if the compiler lacks "unsigned char".
  9.  * It should be a mask, e.g. 0377 for an 8-bit machine.
  10.  */
  11.  
  12. #ifdef NULL
  13. #undef NULL
  14. #endif
  15.  
  16. #define    NULL    0
  17.  
  18. #ifndef CHARBITS
  19. #    define    UNSCHAR(c)    ((unsigned char)(c))
  20. #    define  uchar        unsigned char
  21. #else
  22. #    define    UNSCHAR(c)    ((c)&CHARBITS)
  23. #    define  uchar        char
  24. #endif
  25.  
  26. _VOIDSTAR
  27. lmemccpy(dst, src, ucharstop, size)
  28. _VOIDSTAR dst;
  29. _CONST _VOIDSTAR src;
  30. int ucharstop;
  31. long size;
  32. {
  33.     register char *d;
  34.     register _CONST char *s;
  35.     register long n;
  36.     register int uc;
  37.  
  38.     if (size <= 0L)
  39.         return(NULL);
  40.  
  41.     s = src;
  42.     d = dst;
  43.     uc = UNSCHAR(ucharstop);
  44.     for (n = size; n > 0; n--)
  45.         if (UNSCHAR(*(uchar *)d++ = *(uchar *)s++) == uc)
  46.             return(d);
  47.  
  48.     return(NULL);
  49. }
  50. #endif /* __MSHORT__ */
  51. #endif /* __GNUC__   */
  52.